<!--
登录
1.@click="submit('ruleForm')" 登录
2.@click="quilt()" 清除 token
3.ruleForm 用 输入框 v-model 绑定账号和密码

-->
<template>
  <div class="content">
    <div class="login-content">
      <a href="#" class="banner-box"></a>

      <div class="login-box">
        <h1>注册</h1>
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-position="top" label-width="70px"
          class="login-form">
          <el-form-item label="手机号" prop="Phone_Number" class="_lbl_item">
            <el-input type="text" v-model="ruleForm.Phone_Number"></el-input>
          </el-form-item>

          <el-form-item label="密码" prop="Password" class="_lbl_item">
            <el-input type="password" v-model="ruleForm.Password" autocomplete="off"></el-input>
          </el-form-item>

          <el-form-item class="btn-box">
            <el-button type="primary" @click="submit('ruleForm')" class="login-btn">注册</el-button>
            <!-- <el-button @click="quilt()" class="login-btn">退出</el-button> -->
            <el-button @click="prevPage()" class="login-btn">返回</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>

</template>


<script>
import { signup } from '@/api/user'
export default {
  data() {
    const validataPhone = (rule, value, callback) => {
      const regExp = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/;
      if (!regExp.test(value)) {
        callback(new Error("请输入正确的手机号"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        Phone_Number: "13838383387",
        Password: "12345678"
      },
      rules: {
        Phone_Number: [
          { validator: validataPhone, trigger: "blur" },
        ],
        Password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      },
    }
  },
  methods: {
    //清除token
    // quilt(){
    //   console.log("2");
    //   if(localStorage.getItem("token")!=null){
    //   localStorage.removeItem('token')
    //   this.$message({
    //             message:"退出成功",
    //             type:"success"
    //           });
    //           this.$router.push("/");
    //         }else{
    //           this.$message({
    //             message:"你尚未登录",
    //             type:"error"
    //           });
    //         }
    // },
    prevPage() {
      this.$router.push("/login");
    },

    //注册
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          signup(this.ruleForm).then((res) => {
            console.log(res)
            if (res.code == 200) {
              this.$message({
                message: "注册成功",
                type: "success"
              });
              this.$router.push("/login");
            } else {
              console.log(res.data)
              this.$message({
                message: res.data,
                type: "error",
              })
            }
          })
        }
      })
    }
  }

}


</script>

<style scoped>
* {
  /* 初始化
    设置标准 */
  margin: 0;
  padding: 0;

  font-family: Microsoft Yahei UI, serif;
}

.content {
  width: 100vw;
  /* 100%的窗口高度 */
  height: 100vh;
  /* background-color: aqua; */
  background: url(../assets/背景3.jpg) no-repeat;
  /* 背景大小 */
  background-size: cover;
  /* 弹性布局 水平加 垂直居中 */
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-content {
  display: flex;
  width: 800px;
  height: 360px;
  background: #2d2e2ebb;
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-radius: 15px;
  box-shadow: 0 0 15px #000b;
  padding: 30px;
  /* background: url(./12313.webp) no-repeat; */
  /* background-size: cover; */
  /* border-radius: 20px 0 0 20px; */
}

.banner-box {
  /* 转为块级模块 */
  display: inline-block;
  width: 500px;
  height: 100%;
  background: url(../assets/背景3.jpg) no-repeat;
  background-size: cover;
  box-shadow: 0 0 15px #3f6c7f;
  margin-right: 20px;
  border-radius: 15px;
}

.login-box {
  width: auto;
  height: 100%;
  display: block;
  margin: 0 auto;
}

.login-box>h1 {
  font-size: 24px;
  color: #ffffff;
  text-align: center;
  margin: 10px 0;
}

.login-box>input {
  margin-bottom: 20px;
  height: 36px;
  padding: 0 20px;
  border-radius: 36px;
  border: none;
  font-size: 18px;
}

.btn-box {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

.btn-box button {
  padding: 5px;
  width: 100px;
  font-size: 16px;
}

.login-form {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
}

.login-form>div {
  margin: 5px 0;
}
.login-btn{
    margin-top: 20px;
    width: 200px;
    height: 40px;
    background-color:#807d82;
    border: none;
    border-radius: 20px;
    color: rgb(249, 246, 246);
    font-size: 18px;
}

@media screen and (max-width:860px) {
  .content {
    background: url(../assets/背景3.jpg) no-repeat center cover;
  }

  .login-content {
    margin: 0 100px;
  }

  .banner-box {
    display: none;
  }

  .login-box {
    margin: 0 auto;
  }
}
</style>